/**
*
* 2007-11-2 上午10:39:30
* @author xuhuan
*/

package edu.ccut.saturn.studio.wfg.utils;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import edu.ccut.saturn.studio.core.util.xml.SaturnW3CUtil;
import edu.ccut.saturn.studio.wfg.model.Shape;
import edu.ccut.saturn.studio.wfg.xml.loader.ConnectionLoader;
import edu.ccut.saturn.studio.wfg.xml.loader.NodeLoader;

public abstract class ModelXmlUtils {
	
	public static List<Shape> loadModels(Document document, NodeLoader[] loaders) {
		List<Shape> shapes = new ArrayList<Shape>();
		Element root = document.getDocumentElement();
		
		for (NodeLoader loader : loaders) {
			shapes.addAll(loader.loadNodes(root));
		}
		
		new ConnectionLoader().loadNodeForConnection(root, shapes);
		return shapes;
	}
	
	public static void refreshModelXml(Document document, List<Shape> shapes) {
	
		SaturnW3CUtil.clearDocument(document);
		for (Shape shape : shapes) {
			shape.refresh(document);
		}
		
		SaturnW3CUtil.format(document.getDocumentElement());
	}
	
}
